﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DomainModel;
using WebClasses.Pages;

public partial class Admin_SiteInfoConfig : NormalPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ddlStyle.Items.Clear();
            string[] names = Enum.GetNames(typeof(SiteStyle));
            foreach (string sty in names)
            {
                ddlStyle.Items.Add(new ListItem(sty, ((int)Enum.Parse(typeof(SiteStyle), sty)).ToString()));
            }
            
            
            InitData();
        }
    }

    private void InitData()
    {
        txtAddress.Text = SiteConfig.Singleton.Address;
        txtBackupNum.Text = SiteConfig.Singleton.BackupNumber;
        txtCopyriht.Text = SiteConfig.Singleton.CopRright;
        txtDescription.Text = SiteConfig.Singleton.Description;
        txtEmail.Text = SiteConfig.Singleton.Email;
        txtFax.Text = SiteConfig.Singleton.Fax;
        txtHomeUrl.Text = SiteConfig.Singleton.Url;
        txtKeywords.Text = SiteConfig.Singleton.KeyWord;
        txtPostCode.Text = SiteConfig.Singleton.PostCode;
        txtRegisterNum.Text = SiteConfig.Singleton.RegisterNumber;
        txtTel.Text = SiteConfig.Singleton.Telephone;
        txtTitle.Text = SiteConfig.Singleton.SiteName;

        ddlStyle.Items.FindByValue(SiteConfig.Singleton.Style.ToString()).Selected = true;
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        SiteConfig.Singleton.Address = txtAddress.Text;
        SiteConfig.Singleton.BackupNumber = txtBackupNum.Text;
        SiteConfig.Singleton.CopRright = txtCopyriht.Text;
        SiteConfig.Singleton.Description = txtDescription.Text;
        SiteConfig.Singleton.Email = txtEmail.Text;
        SiteConfig.Singleton.Fax = txtFax.Text;
        SiteConfig.Singleton.Url = txtHomeUrl.Text;
        SiteConfig.Singleton.KeyWord = txtKeywords.Text;
        SiteConfig.Singleton.PostCode = txtPostCode.Text;
        SiteConfig.Singleton.RegisterNumber = txtRegisterNum.Text;
        SiteConfig.Singleton.Telephone = txtTel.Text;
        SiteConfig.Singleton.SiteName = txtTitle.Text;
        SiteConfig.Singleton.Style = int.Parse(ddlStyle.SelectedValue);

        this.LogicController.AdminManager.UpdateSiteConfig(SiteConfig.Singleton);
    }
}
